package cn.jit.util;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;


public class ResponseUtil {

    public static void write(HttpServletResponse response, Object o)  {
        response.setContentType("text/plain;charset=utf-8");
        response.addHeader("Access-Control-Allow-Origin", "*");
        PrintWriter out;
		try {
			out = response.getWriter();
			out.println(o.toString());
	        out.flush();
	        out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
    }
    
    public static void writeHtml(HttpServletResponse response, Object o)  {
        response.setContentType("text/html;charset=utf-8");
        response.addHeader("Access-Control-Allow-Origin", "*");
        PrintWriter out;
		try {
			out = response.getWriter();
			out.println(o.toString());
	        out.flush();
	        out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
    }
    
    
    public static void writeJson(HttpServletResponse response, Object o)  {
        response.setContentType("application/json;charset=utf-8");
        response.addHeader("Access-Control-Allow-Origin", "*");
        PrintWriter out;
		try {
			out = response.getWriter();
			out.println(o.toString());
	        out.flush();
	        out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
    }
    
}
